package info.techgeek.labs.threads;

import java.util.Collection;
import java.util.LinkedList;

public class Computation extends Thread{
	
	private int num;
	private boolean isComplete;
	private int result;
	
	public Computation(int num){
		this.num = num;
	}

	public synchronized void run(){
		System.out.println(num+ " " + this.getName());
		result = num *2;
		isComplete = true;
		notify();
	}
	
	public synchronized int getResult(){
		System.out.println("getResult " + this.getName());
		while(!isComplete){
			System.out.println(isComplete + " " + this.getName());
//			try{
//				wait();
//			}catch (InterruptedException e) {
//				// TODO: handle exception
//			}
		}
		return result;
	}
	
	public static void main(String[] args) {
		
		Computation[] computations =  new Computation[1000];
		
		for(int i = 0; i < computations.length;i++){
			computations[i] =  new Computation(i);
			computations[i].start();
		}
		
		for(Computation c : computations){
			System.out.println(c.getResult()+ " ");
		}
		
	}
	
}
